package com.health.manage.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.health.manage.pojo.dto.PhysicalDto;
import com.health.manage.pojo.entity.Physical;
import com.health.manage.service.IPhysicalService;
import com.health.manage.util.DateUtils;
import com.health.manage.util.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 *
 * @Description: 身体指标管理控制器
 * @author: user
 */
@RestController
@RequestMapping("/physical")
@Api(tags = "身体指标管理")
@CrossOrigin
public class PhysicalController extends BaseController{

    @Autowired
    private IPhysicalService physicalService;

    @PostMapping("list")
    @ApiOperation(value = "获取列表数据", notes = "", httpMethod = "POST")
    public ResponseResult<Page<Physical>> list(@RequestBody PhysicalDto physicalDto){

        Page<Physical> dataList = this.physicalService.getPageData(physicalDto);
        return ResponseResult.success(dataList);
    }

    @PostMapping("add")
    @ApiOperation(value = "添加数据", notes = "", httpMethod = "POST")
    public ResponseResult<Boolean> add(@RequestBody Physical physical){

        physical.setCreateDate(DateUtils.getDate());
        physical.setCreateId(this.currentUser().getId()+"");
        Boolean result = this.physicalService.addData(physical);
        return ResponseResult.success(result);
    }

    @PostMapping("update")
    @ApiOperation(value = "更新数据", notes = "", httpMethod = "POST")
    public ResponseResult<Boolean> update(@RequestBody Physical physical){

        Boolean result = this.physicalService.updateData(physical);
        return ResponseResult.success(result);
    }

    @DeleteMapping("{id}")
    @ApiOperation(value = "删除数据", notes = "", httpMethod = "DELETE")
    public ResponseResult<Boolean> delete(@PathVariable Long id){

        Boolean result = this.physicalService.deleteData(id);
        return ResponseResult.success(result);
    }



}
